app.config([
	'$stateProvider',
	'$urlRouterProvider',
	'$controllerProvider',
	'$compileProvider',
	'$filterProvider',
	'$provide',
	'$ocLazyLoadProvider',
	'JS_REQUIRES',
	function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $ocLazyLoadProvider, jsRequires) {
		var loadSequence;
		loadSequence = void 0;
		app.controller = $controllerProvider.register;
		app.directive = $compileProvider.directive;
		app.filter = $filterProvider.register;
		app.factory = $provide.factory;
		app.service = $provide.service;
		app.constant = $provide.constant;
		app.value = $provide.value;

		$ocLazyLoadProvider.config({ debug: false, events: true, modules: jsRequires.modules });

		loadSequence = function () {
			var _args;
			_args = void 0;
			_args = arguments;
			return {
				deps: [
					'$ocLazyLoad',
					'$q',
					function ($ocLL, $q) {
						var i,
							len,
							promise,
							promiseThen,
							requiredData;
						i = void 0;
						len = void 0;
						promise = void 0;
						promiseThen = void 0;
						requiredData = void 0;
						promise = $q.when(1);
						promiseThen = function (_arg) {
							if (typeof _arg === 'function') {
								return promise.then(_arg);
							} else {
								return promise.then(function () {
									var nowLoad;
									nowLoad = void 0;
									nowLoad = requiredData(_arg);
									if (!nowLoad) {
										console.log('Route resolve: Bad resource name [' + _arg + ']');
									}
									return $ocLL.load(nowLoad);
								});
							}
						};
						requiredData = function (name) {
							var m;
							m = void 0;
							if (jsRequires.modules) {
								for (m in jsRequires.modules) {
									m = m;
									if (jsRequires.modules[m].name && jsRequires.modules[m].name === name) {
										return jsRequires.modules[m];
									}
								}
							}
							return jsRequires.scripts && jsRequires.scripts[name];
						};
						i = 0;
						len = _args.length;
						while (i < len) {
							promise = promiseThen(_args[i]);
							i++;
						}
						return promise;
					}
				]
			};
		};

		function loadByParams($stateParams) {
			console.log('$stateParams', $stateParams.params);
		};

		function loadHtml(path_name, pathname) {
			// console.log('path_name', path_name)
			var htmlUrl;
			if (!pathname) {
				htmlUrl = '../components/' + path_name + '/' + path_name + '.html?version=' + version;
			} else {
				htmlUrl = '../components/' + pathname + '/' + path_name + '/' + path_name + '.html?version=' + version;
			}

			return htmlUrl;
		};

		$stateProvider
			// 首页
			.state('home', {
				url: '/home',
				// abstract: true,
				templateUrl: loadHtml('home'),
				prefetchTemplate: false,
				resolve: loadSequence('home')
			})

			// 用户反馈
			.state('feedback', {
				url: '/feedback',
				templateUrl: loadHtml('feedback'),
				prefetchTemplate: false,
				resolve: loadSequence('feedback')
			})

			// 所有服务
			.state('allservice', {
				url: '/allservice',
				templateUrl: loadHtml('allservice'),
				prefetchTemplate: false,
				resolve: loadSequence('allservice')
			})

			// 用户协议
			.state('agreement', {
				url: '/agreement',
				templateUrl: loadHtml('agreement'),
				prefetchTemplate: false,
				resolve: loadSequence('agreement')
			})

			// 隐私声明
			.state('privacy', {
				url: '/privacy',
				templateUrl: loadHtml('privacy'),
				prefetchTemplate: false,
				resolve: loadSequence('privacy')
			})

			// 注册
			.state('register', {
				url: '/register',
				templateUrl: loadHtml('register', 'auth'),
				prefetchTemplate: false,
				resolve: loadSequence('register')
			})

			// 登录
			.state('login', {
				url: '/login',
				templateUrl: loadHtml('login', 'auth'),
				prefetchTemplate: false,
				resolve: loadSequence('login')
			})

			// 忘记密码 - 手机号或邮箱
			.state('forgetcode', {
				url: '/forgetcode',
				templateUrl: loadHtml('forgetcode', 'auth'),
				prefetchTemplate: false,
				resolve: loadSequence('forgetcode')
			})

			// 忘记密码
			.state('forget', {
				url: '/forget/:data',
				templateUrl: loadHtml('forget', 'auth'),
				prefetchTemplate: false,
				resolve: loadSequence('forget')
			})

			// 预定服务
			// 预定服务
			.state('reservation', {
				url: '/reservation',
				// abstract: true,
				templateUrl: loadHtml('reservation'),
				prefetchTemplate: false,
				resolve: loadSequence('angular-flatpickr', 'reservation')
			})

			// 预定服务 - 需求
			.state('reservation.demand', {
				url: '/demand',
				views: {
					'right': {
						templateUrl: loadHtml('demand', 'reservation'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('demand')
			})

			// 预定服务 - 信息
			.state('reservation.information', {
				url: '/information',
				views: {
					'right': {
						templateUrl: loadHtml('information', 'reservation'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('information')
			})

			// 预定服务 - 预约
			.state('reservation.appointment', {
				url: '/appointment',
				views: {
					'right': {
						templateUrl: loadHtml('appointment', 'reservation'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('appointment')
			})

			// 服务商
			.state('service', {
				url: '/service',
				templateUrl: loadHtml('service'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'uploadCtrl', 'service')
			})

			// 服务商 - 所有订单
			.state('service-allorders', {
				url: '/allorders',
				templateUrl: loadHtml('allorders'),
				prefetchTemplate: false,
				resolve: loadSequence('allorders')
			})

			// 服务商 - 地图订单
			.state('service-maporders', {
				url: '/maporders/:id',
				templateUrl: loadHtml('maporders'),
				prefetchTemplate: false,
				resolve: loadSequence('maporders')
			})

			// 商户主页
			.state('merchant', {
				url: '/merchant/:id',
				// abstract: true,
				templateUrl: loadHtml('merchant'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'merchant')
			})

			// 品牌商
			.state('brand', {
				url: '/brand',
				templateUrl: loadHtml('brand'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'uploadCtrl', 'brand')
			})

			// 新-我的订单的订单详情
			.state('orderDetail', {
				url: '/orderDetail/:id',
				templateUrl: loadHtml('orderDetail'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'uploadCtrl', 'ping', 'angular-flatpickr', 'orderDetail')
			})

			// 新-审核订单的订单详情
			.state('reviewDetail', {
				url: '/reviewDetail/:id',
				templateUrl: loadHtml('reviewDetail'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'uploadCtrl', 'ping', 'angular-flatpickr', 'reviewDetail')
			})

			// 新-我的订单 - 产品信息
			.state('productInfo', {
				url: '/productInfo/:id',
				templateUrl: loadHtml('productInfo'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'print', 'productInfo')
			})

			// 用户中心
			// 用户中心
			.state('mine', {
				url: '/mine',
				templateUrl: loadHtml('mine'),
				prefetchTemplate: false,
				resolve: loadSequence('zoom', 'mine')
			})

			// 根据参数返回对应的页面和控制器
			.state('mine.list', {
				url: '/list/:ctrl',
				views: {
					'mineDetail': {
						prefetchTemplate: false,
						templateUrl: function ($stateParams) {
							return loadHtml($stateParams.ctrl.split(',').pop(), 'mine');
						}
					}
				},
				resolve: {
					loadMyCtrlByCtrl: [
						'$ocLazyLoad',
						'$stateParams',
						function ($ocLazyLoad, $stateParams) {
							var arr = $stateParams.ctrl.split(',');
							var len = arr.length;
							var pathname = arr.pop();
							var loadarr = [];
							if (len >= 2) {
								angular.forEach(jsRequires.scripts, function (v, k) {
									angular.forEach(arr, function (a, b) {
										if (a == k) {
											loadarr.push(v);
										}
									});
								});
							}
							var path = '../components/mine/';
							function load() {
								path = path + pathname + '/' + pathname;
								return [
									path + '.js',
									path + '.css'
								]
							}
							return $ocLazyLoad.load(loadarr.concat(load()));
						}
					]
				}
			})

			// 待审核订单 - 订单详情
			.state('mine.revieworder', {
				url: '/review/:id',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('revieworder', 'mine/review'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('zoom', 'revieworder')
			})

			// 我的订单 - 修改订单
			.state('mine.changeorder', {
				url: '/order/:id/:isreview',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('changeorder', 'mine'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('changeorder')
			})

			// 我的订单 - 渠道
			//     .state('mine.canal', {
			//     url: '/canal',
			//     views: {
			//         'mineDetail': {
			//             templateUrl: loadHtml('canal', 'mine'),
			//             prefetchTemplate: false
			//         }
			//     },
			//     resolve: loadSequence('canal')
			// })

			// 我的订单 - 产品信息
			// .state('mine.productinfo', {
			//     url: '/productinfo/:id',
			//     views: {
			//         'mineDetail': {
			//             templateUrl: loadHtml('productinfo', 'mine'),
			//             prefetchTemplate: false
			//         }
			//     },
			//     resolve: loadSequence('productinfo')
			// })

			// 我的订单 - 订单详情
			.state('mine.orderdetail', {
				url: '/orders/:id/:time',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('orderdetail', 'mine/orders'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('zoom', 'ping', 'angular-flatpickr', 'orderdetail')
			})

			// 发票管理 - 发票详情
			.state('mine.invoiceDetail', {
				url: '/invoice/:id/detail',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('invoiceDetail', 'mine/invoice'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('invoiceDetail')
			})

			// 发票管理 - 开发票
			.state('mine.newInvoice', {
				url: '/invoice/new',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('newInvoice', 'mine/invoice'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('newInvoice')
			})


			// 我的订单 - 订单支付
			.state('mine.orderpay', {
				url: '/pay/:id',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('orderpay', 'mine/orders'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('orderpay')
			})

			// 品牌设置 - 品牌添加
			.state('mine.brandadd', {
				url: '/brandadd/:department/:type',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('brandadd', 'mine/brandset'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('brandadd')
			})

			// 我的钱包 - 充值
			.state('mine.recharge', {
				url: '/recharge/:money',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('recharge', 'mine/money'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('ping', 'recharge')
			})
			// 我的钱包 -  明细
			.state('mine.moneyDetail', {
				url: '/moneyDetail/:start&:end&:type&',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('moneyDetail', 'mine/money'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('moneyDetail')
			})

			// 我的钱包 - 提现
			.state('mine.cash', {
				url: '/cash',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('cash', 'mine/money'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('cash')
			})

			// 更多功能 - 添加
			.state('mine.functions_add', {
				url: '/add/:id',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('functions_add', 'mine/functions'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('functions_add')
			})

			// 更多功能 - 详情
			.state('mine.functions_detail', {
				url: '/detail',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('functions_detail', 'mine/functions'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('functions_detail')
			})

			// 更多功能 - 节点设置
			.state('mine.node', {
				url: '/node',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('node', 'mine/functions'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('node')
			})

			// 更多功能 - 节点设置
			.state('mine.brandnew', {
				url: '/brandnew/:id',
				views: {
					'mineDetail': {
						templateUrl: loadHtml('brandnew', 'mine/functions'),
						prefetchTemplate: false
					}
				},
				resolve: loadSequence('uploadCtrl', 'brandnew')
			})

			// 用户中心 - 个人资料
			// .state('mine.personal', {
			//     url: '/personal',
			//     views: {
			//         'mineDetail': {
			//             templateUrl: loadHtml('personal', 'mine'),
			//             prefetchTemplate: false
			//         }
			//     },
			//     resolve: loadSequence('uploadCtrl', 'personal')
			// })

			// 用户中心 - 账号设置
			// .state('mine.setting', {
			//     url: '/setting',
			//     views: {
			//         'mineDetail': {
			//             templateUrl: loadHtml('setting', 'mine'),
			//             prefetchTemplate: false
			//         }
			//     },
			//     resolve: loadSequence('bootstrapCtrl', 'setting')
			// })

			// 底部信息
			// 关于我们
			.state('aboutus', {
				url: '/aboutus',
				templateUrl: loadHtml('aboutus', 'footer'),
				prefetchTemplate: false,
				resolve: loadSequence('aboutus')
			})

			// 联系我们
			.state('contact', {
				url: '/contact',
				templateUrl: loadHtml('contact', 'footer'),
				prefetchTemplate: false,
				resolve: loadSequence('contact')
			})

			// 网站地图
			.state('map', {
				url: '/map',
				templateUrl: loadHtml('map', 'footer'),
				prefetchTemplate: false,
				resolve: loadSequence('map')
			})

			// 测试
			.state('test', {
				url: '/test',
				templateUrl: loadHtml('test'),
				prefetchTemplate: false,
				resolve: loadSequence('test')
			})

	}
])
